home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.accessibility.AccessibleState;
- import com.sun.java.swing.event.ChangeEvent;
- import com.sun.java.swing.event.ChangeListener;
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.plaf.TabbedPaneUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Rectangle;
- import java.awt.event.MouseEvent;
- import java.io.Serializable;
- import java.util.Vector;
-
- public class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants {
- protected int tabPlacement;
- protected SingleSelectionModel model;
- private boolean haveRegistered;
- protected ChangeListener changeListener;
- Vector pages;
- protected transient ChangeEvent changeEvent;
- static Class class$com$sun$java$swing$event$ChangeListener;
-
- public JTabbedPane() {
- this(1);
- }
-
- public JTabbedPane(int tabPlacement) {
- this.tabPlacement = 1;
- this.changeListener = null;
- this.changeEvent = null;
- this.setTabPlacement(tabPlacement);
- this.pages = new Vector(1);
- this.setModel(new DefaultSingleSelectionModel());
- this.updateUI();
- }
-
- public Component add(Component component) {
- this.addTab(component.getName(), component);
- return component;
- }
-
- public Component add(Component component, int index) {
- this.insertTab(component.getName(), (Icon)null, component, (String)null, index);
- return component;
- }
-
- public void add(Component component, Object constraints) {
- if (constraints instanceof String) {
- this.addTab((String)constraints, component);
- } else if (constraints instanceof Icon) {
- this.addTab((String)null, (Icon)constraints, component);
- } else {
- this.add(component);
- }
-
- }
-
- public void add(Component component, Object constraints, int index) {
- Icon icon = constraints instanceof Icon ? (Icon)constraints : null;
- String title = constraints instanceof String ? (String)constraints : null;
- this.insertTab(title, icon, component, (String)null, index);
- }
-
- public Component add(String title, Component component) {
- this.addTab(title, component);
- return component;
- }
-
- public void addChangeListener(ChangeListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$com$sun$java$swing$event$ChangeListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$ChangeListener = var10001;
- }
-
- var10000.add(var10001, l);
- }
-
- public void addTab(String title, Icon icon, Component component) {
- this.insertTab(title, icon, component, (String)null, this.pages.size());
- }
-
- public void addTab(String title, Icon icon, Component component, String tip) {
- this.insertTab(title, icon, component, tip, this.pages.size());
- }
-
- public void addTab(String title, Component component) {
- this.insertTab(title, (Icon)null, component, (String)null, this.pages.size());
- }
-
- protected ChangeListener createChangeListener() {
- return new ModelListener(this);
- }
-
- protected void fireStateChanged() {
- Object[] listeners = super.listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$com$sun$java$swing$event$ChangeListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
- } catch (ClassNotFoundException var3) {
- throw new NoClassDefFoundError(((Throwable)var3).getMessage());
- }
-
- class$com$sun$java$swing$event$ChangeListener = var10001;
- }
-
- if (var10000 == var10001) {
- if (this.changeEvent == null) {
- this.changeEvent = new ChangeEvent(this);
- }
-
- ((ChangeListener)listeners[i + 1]).stateChanged(this.changeEvent);
- }
- }
-
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJTabbedPane(this);
- }
-
- return super.accessibleContext;
- }
-
- public Color getBackgroundAt(int index) {
- return ((Page)this.pages.elementAt(index)).getBackground();
- }
-
- public Rectangle getBoundsAt(int index) {
- return super.ui != null ? ((TabbedPaneUI)super.ui).getTabBounds(this, index) : null;
- }
-
- public Component getComponentAt(int index) {
- return ((Page)this.pages.elementAt(index)).component;
- }
-
- public Icon getDisabledIconAt(int index) {
- return ((Page)this.pages.elementAt(index)).disabledIcon;
- }
-
- public Color getForegroundAt(int index) {
- return ((Page)this.pages.elementAt(index)).getForeground();
- }
-
- public Icon getIconAt(int index) {
- return ((Page)this.pages.elementAt(index)).icon;
- }
-
- public SingleSelectionModel getModel() {
- return this.model;
- }
-
- public Component getSelectedComponent() {
- int index = this.getSelectedIndex();
- return index == -1 ? null : this.getComponentAt(index);
- }
-
- public int getSelectedIndex() {
- return this.model.getSelectedIndex();
- }
-
- public int getTabCount() {
- return this.pages.size();
- }
-
- public int getTabPlacement() {
- return this.tabPlacement;
- }
-
- public int getTabRunCount() {
- return super.ui != null ? ((TabbedPaneUI)super.ui).getTabRunCount(this) : 0;
- }
-
- public String getTitleAt(int index) {
- return ((Page)this.pages.elementAt(index)).title;
- }
-
- public String getToolTipText(MouseEvent event) {
- if (super.ui != null) {
- int index = ((TabbedPaneUI)super.ui).tabForCoordinate(this, event.getX(), event.getY());
- if (index != -1) {
- return ((Page)this.pages.elementAt(index)).tip;
- }
- }
-
- return super.getToolTipText(event);
- }
-
- public TabbedPaneUI getUI() {
- return (TabbedPaneUI)super.ui;
- }
-
- public String getUIClassID() {
- return "TabbedPaneUI";
- }
-
- public int indexOfComponent(Component component) {
- for(int i = 0; i < this.getTabCount(); ++i) {
- if (this.getComponentAt(i).equals(component)) {
- return i;
- }
- }
-
- return -1;
- }
-
- public int indexOfTab(Icon icon) {
- for(int i = 0; i < this.getTabCount(); ++i) {
- if (this.getIconAt(i).equals(icon)) {
- return i;
- }
- }
-
- return -1;
- }
-
- public int indexOfTab(String title) {
- for(int i = 0; i < this.getTabCount(); ++i) {
- if (this.getTitleAt(i).equals(title == null ? "" : title)) {
- return i;
- }
- }
-
- return -1;
- }
-
- public void insertTab(String title, Icon icon, Component component, String tip, int index) {
- Icon disabledIcon = null;
- if (icon != null && icon instanceof ImageIcon) {
- disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
- }
-
- this.pages.insertElementAt(new Page(this, this, title != null ? title : "", icon, disabledIcon, component, tip), index);
- if (component != null) {
- component.setVisible(false);
- ((Container)this).addImpl(component, (Object)null, -1);
- }
-
- ((Container)this).invalidate();
- if (this.pages.size() == 1) {
- this.setSelectedIndex(0);
- }
-
- if (!this.haveRegistered && tip != null) {
- ToolTipManager.sharedInstance().registerComponent(this);
- this.haveRegistered = true;
- }
-
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", (Object)null, component);
- }
-
- }
-
- public boolean isEnabledAt(int index) {
- return ((Page)this.pages.elementAt(index)).isEnabled();
- }
-
- public void remove(Component component) {
- int index = this.indexOfComponent(component);
- if (index != -1) {
- this.removeTabAt(index);
- }
-
- }
-
- public void removeAll() {
- this.setSelectedIndex(-1);
- int tabCount = this.getTabCount();
-
- for(int i = 0; i < tabCount; ++i) {
- Component component = this.getComponentAt(i);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", component, (Object)null);
- }
- }
-
- super.removeAll();
- this.pages.removeAllElements();
- }
-
- public void removeChangeListener(ChangeListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$com$sun$java$swing$event$ChangeListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$com$sun$java$swing$event$ChangeListener = var10001;
- }
-
- var10000.remove(var10001, l);
- }
-
- public void removeTabAt(int index) {
- int tabCount = this.getTabCount();
- int selected = this.getSelectedIndex();
- if (selected >= tabCount - 1) {
- this.setSelectedIndex(selected - 1);
- }
-
- Component component = this.getComponentAt(index);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", component, (Object)null);
- }
-
- if (component != null) {
- super.remove(component);
- }
-
- this.pages.removeElementAt(index);
- ((Container)this).invalidate();
- }
-
- public void setBackgroundAt(int index, Color background) {
- ((Page)this.pages.elementAt(index)).setBackground(background);
- ((Component)this).repaint();
- }
-
- public void setComponentAt(int index, Component component) {
- Page page = (Page)this.pages.elementAt(index);
- if (component != page.component) {
- if (page.component != null) {
- synchronized(((Component)this).getTreeLock()){}
-
- try {
- int count = ((Container)this).getComponentCount();
- Component[] children = ((Container)this).getComponents();
-
- for(int i = 0; i < count; ++i) {
- if (children[i] == page.component) {
- ((Container)this).remove(i);
- }
- }
- } catch (Throwable var9) {
- throw var9;
- }
- }
-
- page.component = component;
- ((Container)this).addImpl(component, (Object)null, -1);
- }
-
- }
-
- public void setDisabledIconAt(int index, Icon disabledIcon) {
- ((Page)this.pages.elementAt(index)).disabledIcon = disabledIcon;
- if (!this.isEnabledAt(index)) {
- ((Container)this).invalidate();
- }
-
- }
-
- public void setEnabledAt(int index, boolean enabled) {
- ((Page)this.pages.elementAt(index)).setEnabled(enabled);
- ((Component)this).repaint();
- }
-
- public void setForegroundAt(int index, Color foreground) {
- ((Page)this.pages.elementAt(index)).setForeground(foreground);
- ((Component)this).repaint();
- }
-
- public void setIconAt(int index, Icon icon) {
- Icon oldIcon = ((Page)this.pages.elementAt(index)).icon;
- ((Page)this.pages.elementAt(index)).icon = icon;
- ((Container)this).invalidate();
- this.getAccessibleContext();
- if (oldIcon != icon && super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", oldIcon, icon);
- }
-
- }
-
- public void setModel(SingleSelectionModel model) {
- SingleSelectionModel oldModel = this.getModel();
- if (oldModel != null) {
- oldModel.removeChangeListener(this.changeListener);
- this.changeListener = null;
- }
-
- this.model = model;
- if (model != null) {
- this.changeListener = this.createChangeListener();
- model.addChangeListener(this.changeListener);
- }
-
- ((JComponent)this).firePropertyChange("model", oldModel, model);
- }
-
- public void setSelectedComponent(Component c) {
- int index = this.indexOfComponent(c);
- if (index != -1) {
- this.setSelectedIndex(index);
- } else {
- throw new IllegalArgumentException("component not found in tabbed pane");
- }
- }
-
- public void setSelectedIndex(int index) {
- int oldIndex = this.model.getSelectedIndex();
- this.model.setSelectedIndex(index);
- if (oldIndex >= 0 && oldIndex != index) {
- Page var10000 = (Page)this.pages.elementAt(oldIndex);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleState", AccessibleState.SELECTED, (Object)null);
- }
- }
-
- if (index >= 0 && oldIndex != index) {
- Page var3 = (Page)this.pages.elementAt(index);
- if (super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleState", (Object)null, AccessibleState.SELECTED);
- }
- }
-
- }
-
- public void setTabPlacement(int tabPlacement) {
- if (tabPlacement != 1 && tabPlacement != 2 && tabPlacement != 3 && tabPlacement != 4) {
- throw new IllegalArgumentException("illegal tab placement: must be TOP, BOTTOM, LEFT, or RIGHT");
- } else {
- if (this.tabPlacement != tabPlacement) {
- int old = this.tabPlacement;
- this.tabPlacement = tabPlacement;
- ((JComponent)this).firePropertyChange("tabPlacement", old, tabPlacement);
- ((Container)this).invalidate();
- }
-
- }
- }
-
- public void setTitleAt(int index, String title) {
- String oldTitle = ((Page)this.pages.elementAt(index)).title;
- ((Page)this.pages.elementAt(index)).title = title;
- ((Container)this).invalidate();
- if (oldTitle != title && super.accessibleContext != null) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", oldTitle, title);
- }
-
- }
-
- public void setUI(TabbedPaneUI ui) {
- super.setUI(ui);
- }
-
- public void updateUI() {
- int count = this.getTabCount();
-
- while(count-- > 0) {
- Page page = (Page)this.pages.elementAt(count);
- Component component = page.component;
- if (component.getParent() != this && component instanceof Container) {
- page.needsUIUpdate = true;
- } else {
- page.needsUIUpdate = false;
- }
- }
-
- this.setUI((TabbedPaneUI)UIManager.getUI(this));
- }
- }
-